//
//  vdParticleEmitter.h
//  Void Dead
//
//  Created by Sidney Just on 21.11.09.
//
//  Copyright © 2009 by Sidney Just
//  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
//  documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
//  the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 
//  and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
//  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
//  PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
//  FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
//  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#import <Foundation/Foundation.h>

#import "vdNode.h"
#import "vdTexNode.h"
#import "vdShapeContainer.h"

#define ROTATION 1
#define ROTATE 2

// \cond

typedef struct {
	float lifespan;
	
	float pos_x;
	float pos_y;
	
	float gain_X;
	float gain_Y;
	
	float rotation;
	
	float gainSize;
	
	BOOL bright;

	float tPos_x;
	float tPos_y;
	
	float currForceX;
	float currForceY;
	
	vdInlineShape *shape;
} vdParticle;

// \endcond

/**
 * Class that can spawn and handle particles.
 **/
@interface vdParticleEmitter : vdNode {
	//\cond
	int maxParticles;
	
	float lifespan;
	BOOL spawn;
	
	float gain_X;
	float gain_Y;
	
	float randomX;
	float randomY;
	
	float gravityX;
	float gravityY;
	
	float gainSize;
	float rotSpeed;
	
	int spawnPerFrame;
	
	BOOL bright;
	
	float globalLifespan;
	
	unsigned int pFlags;
	
	@private
	BOOL stopSpawn;
	
	vdShapeContainer *container;
	
	vdParticle **particles;
	int particleCount;
	//\endcond
}

//@property (nonatomic, assign) vdTexNode *texture;

/**
 * This variable will be added to the rotation variable of the particle every frame!
 * @remark The ROTATE flag must be set to the emitter!
 * @remark The rotation will be set in degrees!
 **/
@property float rotSpeed;

/**
 * Some extra flags that are only available for emitters. Flags are:
 * <br>ROTATION = The particle will have a random orientation when it spawns
 * <br>ROTATE = The particle will rotate during his life (see rotSpeed variable)
 **/
@property unsigned int pFlags;

/**
 * The lifespan of the emitter in seconds. If the lifespan is 0, the emitter will stop spawning new particles and after all living particles are died, the emitter will
 * remove itself. If you set this value to -1 the emitter won't remove itself.
 <br> Default: -1
 **/
@property float globalLifespan;

/**
 * If this is set to yes, the alphachannel of the texture will be blended with the background instead of mixing both channels.
 * <br>Default NO
 **/
@property BOOL bright;

/**
 * This value will be added to the scale factor of the vdParticle evrey frame
 **/
@property float gainSize;

/**
 * The particles that should be spawn per frame.
 **/
@property int spawnPerFrame;

/**
 * The max Particles that are visible per frame. The particle count can be lower than this value but not over it.
 **/
@property int maxParticles;

/**
 * YES if the Emitter is allowed to spawn, NO if the emitter mustn't spawn particles.
 **/
@property BOOL spawn;

/**
 * The lifetime of a Particle in seconds. If the lifespan value is 0, a particle will only life for one frame
 **/
@property float lifespan;

/**
 * This value will be added to the x position of an particle every frame!
 **/
@property float gain_X;

/**
 * This value will be added to the y position of an particle every frame!
 **/
@property float gain_Y;

/**
 * This value will be added every frame to the force_x value of an particle.
 **/
@property float gravityX;

/**
 * This value will be added every frame to the force_y value of an particle.
 **/
@property float gravityY;

/**
 * A random value between -randomX and randomX will be added every frame to the position of an particle. The random value is different vor every particle but doesn't change while the particle lifes
 **/
@property float randomX;

/**
 * A random value between -randomY and randomY will be added every frame to the position of an particle. The random value is different vor every particle but doesn't change while the particle lifes
 **/
@property float randomY;

/**
 * Returns a vdParticleEmitter instance
 @return Pointer to the new vdParticleEmitter.
 **/
+ (vdParticleEmitter *)emitter;

@end
